package cn.lxh.controller.remote;


import cn.lxh.pojo.domain.DriverPoint;
import cn.lxh.remote.api.BigdataFeignApi;
import cn.lxh.remote.pojo.bo.DriverPointBo;
import cn.lxh.result.JSONResult;
import cn.lxh.service.IDriverPointService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * BigdataFeignApiImpl控制层
 */
@RestController
@Slf4j
public class BigdataFeignApiImpl implements BigdataFeignApi {

    @Autowired
    private IDriverPointService driverPointService;

    /**
     * 查询司机行驶坐标集合
     * @param orderNo
     * @return
     */
    @Override
    public JSONResult<List<DriverPointBo>> driverPointList(String orderNo) {
        // 根据订单号查询司机行驶坐标
        List<DriverPoint> driverPointList = driverPointService.selectByOrderNo(orderNo);
        // 假如查询为空, 查询成功, 但是data为空
        if (driverPointList == null || driverPointList.isEmpty()) return JSONResult.success();
        // 将driverPointList集合中的每个对象转换为另一个对象, 创建一个新的集合
        List<DriverPointBo> driverPointBoList = driverPointList.stream().map(p -> new DriverPointBo(p.getLatitude(), p.getLongitude())).collect(Collectors.toList());
        return JSONResult.success(driverPointBoList);
    }
}
